package com.ghost.Chessboard;

import java.util.Vector;


 

class Number{
    int number;
    String id;
    Number(int number,String id){
	this.number=number;
	this.id=id;
	
    }
}

class Seenumber {
    private int number;
    Vector<String> ids=new Vector<String>();

    
    Seenumber(int number){
	this.number=number;
    }
    public void addNumber(Item item) {
	 isiteminadded(item.position.id);
	  
    }
    public int getNumber() {
	return number;
    }
    public boolean isiteminadded(String id) {
	    if (ids.contains(id))
		return true;
	    else{
		ids.add(id);
		this.number+=1;
		return false; 
    
	    }
    }
}

public class Chessboard  {
    private int widthnum;
    private int heightnum;
//    private Seenumber seenumbers_now;
//    private Seenumber seenumbers_should;
    public int[] layout;
    public int[] nowlayout;
    public int[] resultelist	;
    private int[] seelist;
    public Item[][] chessmap;
    
    public Chessboard(int widthnum,int heightnum,int[] layout,int[] resultelist){
	this.setWidthnum(widthnum);
	this.setHeightnum(heightnum);
	this.layout=layout;
	this.nowlayout=layout;
//	this.seenumbers_should=seenumbers_should;
	this.resultelist=resultelist;
	this.seelist=new int[(widthnum+heightnum)*2];
	for(int i = 0; i< seelist.length; i++){
	    seelist[i] = 0;
	}
	chessmap=new Item[this.heightnum ][this.widthnum];
	for(int i = 0; i< this.heightnum; i++){
	    for(int j = 0; j< this.widthnum; j++){
		Pref.sysprint(" ###@@@@layout[i*this.widthnum+j]: "+layout[i*this.widthnum+j]);
		    chessmap[i][j] =new Item(layout[i*this.widthnum+j]);
		}
	     
	}

    }
    public void placeitem(Item item,int x,int y) {
	item.setposition(x, y);
	chessmap[y][x]=item;
	this.nowlayout[y*this.widthnum+x]=item.id;
	
    }
    public boolean check() {
 	for(int i = 0; i< seelist.length; i++){
 	   Pref.sysprint("###i: "+i);
 	    send(i);
 	}
	 
	if (seelist==resultelist)
	    return true;
	
	return false;
   }
    public int[] getseelist() {
	return this.seelist;
    }
    
    public int[] getresultlist() {
	return this.resultelist;
    }
    
    
    public void setWidthnum(int widthnum) {
	this.widthnum = widthnum;
    }
    public int getWidthnum() {
	return widthnum;
    }
    public void setHeightnum(int heightnum) {
	this.heightnum = heightnum;
    }
    public int getHeightnum() {
	return heightnum;
    }
     
    public void send(int startfrom) {
	// TODO Auto-generated method stub
	int startturnstate=checkstartfrom(startfrom);
	int x=0;
	int y=0;
	Pref.sysprint("###startturnstate: "+startturnstate);
	switch (startturnstate) {
	    case 1:
	    {
		x=startfrom;
		y=0;
		break;
		 
	    }
	    case 2:
	    {
		x=startfrom-this.widthnum;
		y=this.heightnum-1;
		break;
	    }
	    case 3:
	    {
		x=0;
		y=startfrom-this.widthnum*2;
		break;
	    }
	    case 4:
	    {
		x=this.widthnum-1;
		y=startfrom-(this.widthnum*2+this.heightnum);
		break;
	    }
	}
	Line l=new Line(startfrom,startturnstate,x,y);
	l.run(this);
	seelist[startfrom]=l.getseecount();
	Pref.sysprint("###see: "+l.getseecount());
	Pref.sysprint("############");

	 

    }
    private int checkstartfrom(int startfrom) {
	if (startfrom>=0 && startfrom < this.widthnum)
	    return 1;
	else if (startfrom>=widthnum && startfrom < (this.widthnum*2))
	    return 2;
	else if (startfrom>=(this.widthnum*2) && startfrom < (this.widthnum*2+this.heightnum))
	    return 3;
	else if (startfrom>=(this.widthnum*2+this.heightnum) && startfrom < (this.widthnum+this.heightnum)*2)
	    return 4;
	return 1;
    }
    
    
 
   
    
    

}
